package com.fireXXX.job.analysis.crawler.common.company;

import com.fireXXX.job.analysis.crawler.boss.constant.CityTypeEnum;
import com.fireXXX.job.analysis.crawler.util.JacksonUtil;
import com.fireXXX.job.analysis.data.api.job.Company;
import com.fireXXX.job.analysis.data.api.job.Job;
import com.fireXXX.job.analysis.datamgr.service.CompanyService;
import com.fireXXX.job.analysis.datamgr.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class CompanyPersister {

    @Autowired
    private CompanyService companyService;

    public void persist(CityTypeEnum city, List<Company> companies) {
        System.out.println(JacksonUtil.toJsonStringSafe(companies));
        for (Company company : companies) {
            company.setCity(city.getText());
            companyService.save(company);
        }
    }

}
